import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
//导入axios
import axios from "axios";
//导入element-plus
import ElementPlus, {ElMessageBox} from 'element-plus'
import 'element-plus/dist/index.css'
//导入qs
import qs from 'qs'
//配置axios的基础路径
axios.defaults.baseURL = 'http://localhost:9000'
const app = createApp(App);
//定义全局对象
app.config.globalProperties.$axios = axios
app.config.globalProperties.$qs = qs
app.use(ElementPlus)
app.use(router).mount('#app')
//请求拦截器
axios.interceptors.request.use( req => {
    console.log('拦截请求',req)
    //读取token
    let token = localStorage.getItem('token')
    //如果不为空，就添加到请求头中
    if(token){
        req.headers.Authorization = token
    }
    return req
})
//响应拦截器
axios.interceptors.request.use(req => {
    console.log("拦截请求",req)
    // 读取token
    let token = localStorage.getItem('token')
    // 如果不为空，就添加到请求头中
    if (token) {
        req.headers.Authorization = token
    }
    return req
})
const api = axios.create({
    baseURL: 'http://localhost:9000', // Your gateway port
    timeout: 5000
});
